package com.sxf.auth.login.controller;

import com.sxf.auth.login.service.LoginService;
import com.sxf.auth.login.service.UserService;
import com.sxf.auth.login.vo.*;
import com.sxf.common.param.ResultInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: TODO
 * @Author Leo
 * @date 2024/3/1622:00
 */
@Api(value = "登陆相关", tags = { "登陆相关" })
@RestController
@Validated
@RequestMapping("/auth")
public class AuthController {

    @Autowired
    UserService userService;
    @Autowired
    LoginService loginService;

    @ApiOperation(value = "修改密码", produces = "application/json", httpMethod = "POST")
    @RequestMapping("/changePassword")
    public ResultInfo<Boolean> changePassword(@Validated @RequestBody ChangePassWordReq req){
        return ResultInfo.success(userService.changePassword(req));
    }

    @ApiOperation(value = "重置密码", produces = "application/json", httpMethod = "POST")
    @RequestMapping("/resetPassword")
    public ResultInfo<Boolean> resetPassword(@Validated @RequestBody ResetPasswordReq req){
        return ResultInfo.success(userService.resetPassword(req));
    }

    @ApiOperation(value = "退出登陆", produces = "application/json", httpMethod = "POST")
    @PostMapping("/logout")
    public ResultInfo<Void> logout(){
        loginService.logout();
        return ResultInfo.success();
    }

    @PostMapping("/op/addUser")
    @ApiOperation(value = "运营端添加用户", produces = "application/json", httpMethod = "POST",hidden = true)
    public ResultInfo<AddUserRes> addOpUser(@RequestBody @Validated AddOpUserReq req) {
        return ResultInfo.success(userService.addOpUser(req));
    }

    @PostMapping("/cm/addUser")
    @ApiOperation(value = "客户管理端添加协调员/审核员", produces = "application/json", httpMethod = "POST",hidden = true)
    public ResultInfo<AddUserRes> addCoorApprUser(@RequestBody @Validated AddCoordinateApproverReq req) {
        return ResultInfo.success(userService.addCoorUser(req));
    }

    @PostMapping("/checkMobile")
    @ApiOperation(value = "受试者是否注册", produces = "application/json", httpMethod = "POST",hidden = true)
    public ResultInfo<ValidUserMobileRes> validUserMobile(@RequestBody @Validated ValidUserMobileReq req) {
        return ResultInfo.success(userService.validUserMobile(req));
    }

    @PostMapping("/updateUserStatus")
    @ApiOperation(value = "更新用户状态", produces = "application/json", httpMethod = "POST",hidden = true)
    public ResultInfo<Boolean> updateUserStatus(@RequestBody @Validated UpdateUserStatusReq req) {
        return ResultInfo.success(userService.updateUserStatus(req));
    }

    @PostMapping("/logOff")
    @ApiOperation(value = "受试者注销账号", produces = "application/json", httpMethod = "POST")
    public ResultInfo<Boolean> logOff(@RequestBody @Validated SubjectsLogOffReq req) {
        return ResultInfo.success(userService.logOff(req));
    }

}
